package hr.pzrinscak.util;

import javax.servlet.http.HttpServletRequest;

public final class StaticUtils {

    public static final String VARIABLE_PACKAGE_ID = "bpmn_packageId";
    public static final String VARIABLE_ACTION = "bpmn_action";
    public static final String VARIABLE_ASSIGNED_BY = "bpmn_assigned_by";
    public static final String PATH_TEMPLATES = "/apis/predlosci";
    public static final String PATH_TEMPLATE_TEMPLATES = "/apis/predlosci_predlozaka";
    public static final String PATH_DOCUMENTS = "/apis/dokumenti";
    public static final String EMAIL_FROM = "alfresco@apis-it.hr";

    public static String getServletContextURL( final HttpServletRequest request) {
        String url = request.getScheme() + "://" + request.getServerName() + ((request.getServerPort() != 0) ? (":" + request.getServerPort()) : "") + request.getContextPath() + request.getServletPath();
        //return request.getRequestURL().substring(0, request.getRequestURL().lastIndexOf("/"));
        return url;
    }

    public static String getProcessKeyFromProcessId( final String processDefinitionId ) {
        int index = processDefinitionId.indexOf(':');
        if (index < 0) {
            return processDefinitionId;
        }
        else {
            return processDefinitionId.substring(0, index);
        }
    }

}
